#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct stu {
    char no[10];
    char name[100];
    char sex[10];
    int age;
} STU;

int isSame(char s1[], char s2[]) {
    int i = 0;
    while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0') {
        i++;
    }
    return s1[i] == s2[i] ? 1 : 0;
}

void helper(STU* t, char no[], int length) {
    for (int i = 0; i < length; i++) {
        if (isSame(t[i].no, no)) {
            printf("%s %s %s %d\n", t[i].no, t[i].name, t[i].sex, t[i].age);
        }
    }
}

int main() {
    int n, search_num;
    FILE* fp = fopen("./data.in", "r");
    while (fscanf(fp, "%d\n", &n) != EOF) {
        STU* tmp = (STU*)malloc(n * sizeof(STU));
        for (int i = 0; i < n; i++) {
            fscanf(fp, "%s %s %s %d\n", tmp[i].no, tmp[i].name, tmp[i].sex,
                   &tmp[i].age);
        }
        fscanf(fp, "%d\n", &search_num);
        char no[10];
        for (int i = 0; i < search_num; i++) {
            fscanf(fp, "%s\n", no);
            helper(tmp, no, n);
        }
    }
}
